package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.popwindow.BasicPopmodule;

/**
 * Created by ${oushuhua} on 2017/7/20.
 */

public class PopShowDialogModule extends BasicPopmodule {

    public Context mContext;
    private popDialogListener poplistener;
    private String mPics;
    private ImageView mImgShowDialogBg;
    private RelativeLayout mRelPopShowDialogModule;
    private RelativeLayout mRelPopShowDialogModuleLayout;
    private DisplayMetrics mDisplaMetrics;
    private int CarSollnum;
    public PopShowDialogModule(Context ctx, String pic, DisplayMetrics dm,int carSollnum, popDialogListener l){
        mContext=ctx;
        mPics=pic;
        mDisplaMetrics=dm;
        this.CarSollnum=carSollnum;
        poplistener=l;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_show_dialog_module, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        mRelPopShowDialogModule=(RelativeLayout)mContentView.findViewById(R.id.rel_pop_show_dialog_module);
        mRelPopShowDialogModuleLayout=(RelativeLayout)mContentView.findViewById(R.id.rel_pop_show_dialog_module_layout);
        mImgShowDialogBg=(ImageView)mContentView.findViewById(R.id.img_show_dialog_bg);
        ImageView mImgShowDialogDelete=(ImageView)mContentView.findViewById(R.id.img_show_dialog_delete);
        TextView mTvShowDialogTitle=(TextView)mContentView.findViewById(R.id.tv_show_dialog_title);
        if (!TextUtils.isEmpty(mPics)){
            Glide.with(mContext).load(mPics).error(R.mipmap.voucher).into(mImgShowDialogBg);
        }else{
            Glide.with(mContext).load(R.mipmap.voucher).error(R.mipmap.voucher).into(mImgShowDialogBg);
        }
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mRelPopShowDialogModuleLayout.getLayoutParams();
        params.width =mDisplaMetrics.widthPixels-(mDisplaMetrics.widthPixels/5);
        params.height=mDisplaMetrics.widthPixels;
        mRelPopShowDialogModuleLayout.setLayoutParams(params);
        mTvShowDialogTitle.setText("      您已获"+CarSollnum+"张清洁券");
        mImgShowDialogBg.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                poplistener.dialogClickTv();
                mPopwindows.dismiss();
            }
        });
        mImgShowDialogDelete.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                poplistener.dialogDismiss();
                mPopwindows.dismiss();
            }
        });
    }

    public interface popDialogListener {
        void dialogClickTv();
        void dialogDismiss();
    }

}
